


import upload from '../../../../public/functions/upload-new';

import {toast} from 'nc-lightapp-front';

import language from '../../language';

export default function() {

    upload({
        name: 'webfiles',
        action: '/nccloud/hrhi/psndoc/PsndocImportPhotoAction.do',
        multiple: true,
        onResult: (res) => {
            if(res.success) {
                toast({
                    color: 'success',
                    content: res.data
                });
            }
            else {
                toast({
                    color: 'danger',
                    content: res.message
                });
            }
        },
        onChange: (e) => {
            let fileList = e.target.files;
            let fileLength = fileList.length;
            let size = 0;
            Array.prototype.map.call(fileList, (file) => {
                size += file.size;
            });

            if(fileLength > 100) {
                toast({
                    color: 'danger',
                    content: language['hi6007-000186'] // 上传文件数量不得多于100个
                });
                return false
            }
            if(size / 1048576 > 20) {
                toast({
                    color: 'danger',
                    content: language['hi6007-000187'] // 上传文件大小不得大于20兆
                });
                return false
            }
            
            return true;
        },
        body: {
            pk_org: this.state.humanResourceOrganizationValue.refpk
        },
        webkitdirectory: true
    });

}